#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    int minSubArrayLen(int s, vector<int> &nums)
    {
        int i = 0, j = 0, ans = 0x7fffffff, csum = 0;
        while (j < nums.size())
        {
            if (csum >= s)
            { 
                ans = min(ans, j - i + 1);
                csum -= nums[i++];
            }
            else if (j < nums.size())
            {
                csum += nums[j++];
            }
        }
        return ans;
    }
};